package com.cashmama.market.api.domain.handler;

import com.cashmama.market.api.infras.consts.RedisKeyConsts;
import com.fqgj.base.services.redis.RedisClient;
import com.fqgj.common.api.Response;
import com.qianli.cashmama.product.facade.ProductFacade;
import com.qianli.cashmama.product.facade.result.ProductCategory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @program: market-api
 * @description 初始化缓存
 * @author: frank
 * @create: 2019-12-26 18:13
 **/
//@Service
public class CacheInitHandler {

    @Autowired
    private ProductFacade productFacade;
    @Autowired
    private RedisClient redisClient;

    //@PostConstruct
    public void InitCategoryCache(){
        try {
            Response<List<ProductCategory>> allActiveProductCategory = productFacade.getAllActiveProductCategory();
            List<ProductCategory> categories = allActiveProductCategory.getData();
            redisClient.set(RedisKeyConsts.ALL_CATEGORY_CACHE_KEY, categories);
        } catch (Exception e) {

        }
    }
}
